package de.tuberlin.dima.dkey.nodes;

public class MultiValueNode implements GNode{

	private static final long serialVersionUID = 1L;
	
	protected int id;
	protected String[] value;
	protected int graph;
	final String type = "MultiValueNode";
	
	public MultiValueNode(){
		throw new UnsupportedOperationException(); 
	}
	
	public MultiValueNode(int graph, int id, String value){
		this.id = id;
		this.value = value.split(";");
		this.graph = graph;
	}
	
	public String getValue() {
		StringBuffer out = new StringBuffer();
		String semi = "";
		for(String item : value){
			out.append(semi + item);
			semi = ";";
		}
		return out.toString();
	}

	public int getId() {
		return id;
	}

	public int getGraph() {
		return graph;
	}
	
	public String getType(){
		return type;
	}
	
	public String getColour(){
		return "green";
	}
	

	public String[] getIndexValues() {
		return this.value;
	}
	//The default is to only compare the String values
	public boolean equals(GNode toEval) {
		//return  this.value.contains(toEval.getValue());
		return equalsIgnoreCase(toEval);
	}
	
	public boolean equalsIgnoreCase(GNode toEval) {
		for (String item : value){
			if(item.toLowerCase().contains(toEval.getValue().toLowerCase())){
				return true;
			}
		}
		return false;
	}	

	
	@Override public String toString() {
		return id + ":"  +value + ":" + graph;
	}
	
	/**
     * Returns the hash code value for this edge.
     *
     * @return the hash code value for this list
     */
    public int hashCode() {
        int hashCode = 1;
        
        hashCode = 31*hashCode + id;
        hashCode = 31*hashCode + value.hashCode();
        
        return hashCode;
    }
	
}
